package chuangyi.com.org.ViewModel;

import android.app.Activity;
import android.content.Context;
import android.databinding.Bindable;
import android.view.View;

import com.umeng.socialize.ShareContent;
import com.umeng.socialize.media.UMImage;

import chuangyi.com.org.DOMIHome.BR;
import chuangyi.com.org.DOMIHome.PopupActivity;
import chuangyi.com.org.DOMIHome.R;
import chuangyi.com.org.DOMIHome.Utils.WebApi;

/**
 * Created by zxh on 16/12/20.
 */

public class AnswerDetail extends ObservableWithGoBackHandler {
    private QuestionItem question;
    private AnswerItem answerItem;

    @Bindable
    public QuestionItem getQuestion() {
        return question;
    }

    @Bindable
    public boolean isMine() {
        return User.getCurrentUser().getUid() == question.getUid();
    }

    @Bindable
    public AnswerItem getAnswerItem() {
        return answerItem;
    }

    public AnswerDetail(Context context, AnswerItem answer) {
        super(context);
        answerItem = answer;
        this.question = answer.getQuestion();
    }

    public void onClickShare(View view) {
        Activity activity = (Activity) getContext();
        ShareModel model = new ShareModel(activity);
        model.setShareType("reward");
        model.setId(getQuestion().getId());
        model.setShareCallback(new ShareModel.Callback() {
            @Override
            public void onShareSuccess() {
            }

            @Override
            public void onShare(ShareItem shareItem) {
                ShareContent content = new ShareContent();
                content.mTitle = ShareModel.SHARE_TITLE;
                content.mText = ShareModel.SHARE_TEXT;
                content.mMedia = new UMImage(getContext(), ShareModel.SHARE_IMG);
                content.mTargetUrl = WebApi.getShareUrl();
                shareItem.setShareData(content);
            }
        });
        PopupActivity.startActivity(activity, R.layout.v_dialog_share, BR.share, model);
    }
}
